
package com.neuedu.yyzx.config;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import com.neuedu.yyzx.entity.User;

import java.time.ZoneOffset;

public class JWTUtil {
    public static final String KEY = "user";
    public static final String PERMISSION_KEY = "umspermission";

    public static String create(User user) {
        return JWT.create()
                .withClaim("username",user.getUsername())
                .withClaim("password",user.getPassword())

                .withClaim("id",user.getId())                //员工的id
                    //部门的id


                .sign(Algorithm.HMAC256(KEY));
    }

    public static void main(String[] args) {
        String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IiQyYSQxMCRvN2hkNzVQY1VkLjFySjcwYmZiR0V1NWFCZEIwTzV6SnNNQlpvNzFwbXZuMXVqNmNZZU8zVyIsImRlcHRJZCI6MiwiaWQiOjIsInVzZXJuYW1lIjoidXNlcjEiLCJ0aW1lc3RhbXAiOjE1OTg1ODIyNjgwNzF9.xn5dNbmW60lOrZncUo3IZg6mcUanOOFb92LV904moTk";
        DecodedJWT decode = JWT.decode(token);

        String id = decode.getClaim("id").asString();

        System.out.println("id:"+id);


    }
}

